﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace Hsp.WebNovels.Model.Models;

public partial class NovelsContext : DbContext
{
    public NovelsContext()
    {
    }

    public NovelsContext(DbContextOptions<NovelsContext> options)
        : base(options)
    {
    }

    /// <summary>
    /// 小说站点信息
    /// </summary>
    public virtual DbSet<WebSite> WebSites { get; set; }

    /// <summary>
    /// 章节信息
    /// </summary>
    public virtual DbSet<Chapter> Chapters { get; set; }

    /// <summary>
    /// 章节内容
    /// </summary>
    public virtual DbSet<Content> Contents { get; set; }

    /// <summary>
    /// 内容替换
    /// </summary>
    public virtual DbSet<Replace> Replaces { get; set; }

    /// <summary>
    /// 小说信息
    /// </summary>
    public virtual DbSet<Novel> Novels { get; set; }


    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseSqlServer("Server=.;Database=WebNovels; Encrypt=True;TrustServerCertificate=True; User ID=sa; Password=sa@123");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {

        modelBuilder.Entity<WebSite>(entity =>
        {
            entity.ToTable("WebSites", tb => tb.HasComment("小说站点信息"));

            entity.HasKey(e => e.Id).HasName("PK_WebSites");

            entity.Property(e => e.Id)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("站点ID");

            entity.Property(e => e.Name)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("站点名称");

            entity.Property(e => e.WebUrl)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("站点地址");

            entity.Property(e => e.AddressObject)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("地址对象");

            entity.Property(e => e.AddressNext)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("下一页地址对象");

            entity.Property(e => e.ContentObject)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("内容对象");

            entity.Property(e => e.ContentNext)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("下一页内容对象");

            entity.Property(e => e.Encoding)
                .HasMaxLength(10)
                .IsUnicode(false)
                .HasComment("站点编码");

            entity.Property(e => e.UrlCombine)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("地址是否需要组合：0-不需要；1-网站地址 + 章节地址；2-小说地址 + 章节地址；");

            entity.Property(e => e.AnnotationType)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("正文类型：0-文本；1-HTML；");

            entity.Property(e => e.Valid)
                .HasColumnType("int")
                .HasDefaultValueSql("'((1))'")
                .HasComment("是否有效：0-否；1-是；");

            entity.Property(e => e.CreateTime)
                .HasComment("添加时间");

            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间");

        });

        modelBuilder.Entity<Chapter>(entity =>
        {
            entity.ToTable("Chapters", tb => tb.HasComment("章节信息"));

            entity.HasKey(e => e.Id).HasName("PK_Chapters");

            entity.HasIndex(e => e.ChapterUrl, "IX_Chapters_ChapterUrl");

            entity.HasKey(e => e.NovelId).HasName("IX_Chapters_NovelId");

            entity.Property(e => e.Id)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("章节编号");

            entity.Property(e => e.NovelId)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("小说编号");

            entity.Property(e => e.ChapterUrl)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("章节地址");

            entity.Property(e => e.NextUrl)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("下一页地址");

            entity.Property(e => e.SourceTitle)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("源标题");

            entity.Property(e => e.ChapterTitle)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("章节标题");

            entity.Property(e => e.ChapterIdx)
                .HasColumnType("int")
                .HasComment("章节索引");

            entity.Property(e => e.ChapterName)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasComment("章节序号");

            entity.Property(e => e.HeadWord)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("标题文本");

            entity.Property(e => e.WordCount)
                .HasColumnType("int")
                .HasComment("章节字数");

            entity.Property(e => e.ValidChapter)
                .HasColumnType("int")
                .HasDefaultValueSql("'((1))'")
                .HasComment("有效章节：0-否；1-是；");

            entity.Property(e => e.CreateTime)
                .HasComment("添加时间");

            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间");

        });

        modelBuilder.Entity<Content>(entity =>
        {
            entity.ToTable("Contents", tb => tb.HasComment("章节内容"));

            entity.HasKey(e => e.ChapterId).HasName("PK_Contents");

            entity.Property(e => e.ChapterId)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("章节ID");

            entity.Property(e => e.NovelId)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("小说ID");

            entity.Property(e => e.Contents)
                //.HasMaxLength(-1)
                .IsUnicode(false)
                .HasComment("章节内容");

            entity.Property(e => e.CreateTime)
                .HasComment("添加时间");

            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间");

        });

        modelBuilder.Entity<Replace>(entity =>
        {
            entity.ToTable("Replaces", tb => tb.HasComment("内容替换表"));

            entity.HasKey(e => e.Id).HasName("PK_Replaces");

            entity.Property(e => e.Id)
                .HasColumnType("int")
                .HasComment("ID");

            entity.Property(e => e.NovelId)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("小说编号");

            entity.Property(e => e.Source)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("源内容");

            entity.Property(e => e.Target)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("替换内容");

            entity.Property(e => e.Priority)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("优先级");

            entity.Property(e => e.Deleted)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("已删除：0-否；1-是；");

            entity.Property(e => e.CreateTime)
                .HasComment("添加时间");

            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间");

        });

        modelBuilder.Entity<Novel>(entity =>
        {
            entity.ToTable("Novels", tb => tb.HasComment("小说信息"));

            entity.HasKey(e => e.Id).HasName("PK_Novels");

            entity.HasIndex(e => e.WebId, "IX_Novels_WebId");

            entity.Property(e => e.Id)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("小说编号");

            entity.Property(e => e.WebId)
                .HasMaxLength(36)
                .IsUnicode(false)
                .HasComment("网站编号");

            entity.Property(e => e.Title)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("小说标题");

            entity.Property(e => e.NovelUrl)
                .HasMaxLength(255)
                .IsUnicode(false)
                .HasComment("小说地址");

            entity.Property(e => e.Author)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasComment("作者");

            entity.Property(e => e.Status)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("小说状态：0-连载中；1-已完本；2-已太监；");

            entity.Property(e => e.ChapterChar)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasComment("章节模板，如第$2章");

            entity.Property(e => e.ChapterCount)
                .HasColumnType("int")
                .HasDefaultValueSql("'((0))'")
                .HasComment("章节数量");

            entity.Property(e => e.CreateTime)
                .HasComment("添加时间");

            entity.Property(e => e.UpdateTime)
                .HasComment("更新时间");

        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
